package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationInserDto;
import com.zzyl.nursing.service.MemberReservationService;
import com.zzyl.nursing.vo.AppointmentsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;

@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约接口")
public class MemberReservationController extends BaseController {
    @Autowired
    private MemberReservationService memberReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation(value = "查询用户当天取消预约数量")
    public AjaxResult getCancelledCount(){
        return AjaxResult.success(memberReservationService.getCancelledCount());
    }

    @GetMapping("/countByTime")
    @ApiOperation(value = "查询每个时间段剩余预约次数")
    public R<List<AppointmentsVo>> getCountByTime(Long time){
        LocalDate localDate = Instant.ofEpochMilli(time).atZone(ZoneId.systemDefault()).toLocalDate();
        List<AppointmentsVo> list = memberReservationService.getCountByTime(localDate);
        return R.ok(list);
    }

    @PostMapping
    @ApiOperation(value = "新增预约")
    public AjaxResult addReservation(@RequestBody ReservationInserDto dto){
        memberReservationService.addReservation(dto);
        return AjaxResult.success("添加预约成功");
    }
}
